import { http } from '@/plugins/axios'
import { defineStore } from 'pinia'

export default defineStore('user-store', {
  state: () => {
    return {
      userInfo: getUserInfo(),
      token: useStorage().get(CacheEnum.TOKEN_NAME) || '',
      loginLoading: false,
    }
  },
  getters: {
    /** 是否登录 */
    isLogin(state) {
      return Boolean(state.token)
    },
  },
  actions: {
    async getCurrentUser() {
      if (useAuth().isLogin()) {
        this.userInfo = await http.request<UserModel>({
          url: `auth/login`,
        })
      }
    },
  },
})
